//
//  RYBaseCell.swift
//  App_Profile
//
//  Created by 蒋晨成 on 2022/2/8.
//

import Adaptor
import App_Common_UIKitExtensions
import App_Common_Views
import Chain
import Foundation
import UICore
import UIKit

public class RYBaseCell: CollectionViewCell {
    var cellModel: RYBaseCellModel?

    lazy var indicatorImageView: UIImageView = .init()
        .x
        .image(ProfileModular.image(named: "Common.Cell.Indicator")?.withTintColor(Adaptor.Profile.Setting.detailTextColor))
        .instance

    lazy var lineView: UIView = LineView(frame: .zero, lineColor: Adaptor.Profile.lineBorderColor, lineWidth: 1.0)
        .x
        .instance

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    @available(*, unavailable)
    required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") }

    func reusableCell(_ cellModel: RYBaseCellModel) {
        self.cellModel = cellModel
        indicatorImageView.isHidden = cellModel.isHiddenIndicator
    }
}

private extension RYBaseCell {
    func setupUI() {
        lineView.x.add(to: contentView).snp.makeConstraints {
            $0.leading.equalToSuperview()
            $0.trailing.equalToSuperview()
            $0.height.equalTo(1)
            $0.bottom.equalToSuperview()
        }

        indicatorImageView.x.add(to: contentView).snp.makeConstraints {
            $0.trailing.equalToSuperview().offset(-20)
            $0.centerY.equalToSuperview()
        }
    }
}
